package org.megha.blog.example.concurrency;

/**
 * Creates two threads, each one prints As or Bs.
 * 
 * @author megha birmiwal
 */
public class PrintABs {
	
	public static class PrinterThread extends Thread {		
		
		private int times;
		private String message;
		
		public PrinterThread(int times, String message) {
			this.times = times;
			this.message = message;
		}
		
		@Override
		public void run() {
			for (int i = 0; i < times; i++) {
				System.out.println(message);
			}
		}
	}
	
	public static void main(String args[]) {
		PrinterThread printerThread1 = new PrinterThread(1000, "A");
		printerThread1.start();
		PrinterThread printerThread2 = new PrinterThread(1000, "B");
		printerThread2.start();
				
		try {
			printerThread1.join();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		try {
			printerThread2.join();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
